package io.renren.modules.wcs.listenSlaveDB.controller;

import io.renren.datasource.annotation.DataSource;

import io.renren.modules.wcs.listenSlaveDB.dao.TestDaos;
import io.renren.modules.wcs.listenSlaveDB.entity.TestEntity2;
import io.renren.modules.wcs.listenSlaveDB.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author: 蔡翔
 * @Date: 2019/9/29 9:47
 * @Version 1.0
 */
@Component
public class TestBean {
    @Autowired
    TestDaos testDaos;

    @Autowired
    TestService testService;

    //使用@DataSource("slave1") 这个注解之前必须 把这个方法所存在的类也 注入到spring 容器中去。
    @DataSource("slave1")
    public Integer count(){
        //Integer count = testDaos.selectCount();
        Integer count = testService.count();
        return count;
    }

    @DataSource("slave1")
    public List<TestEntity2> selectAll(){
        return testService.list();
    }

    @DataSource("slave1")
    public Integer insertOne(TestEntity2 testEntity){
        return testService.getBaseMapper().insert(testEntity);
    }

    @DataSource("slave1")
    public Integer deleteByBatchName(List<Integer> ids){
        int i = testService.getBaseMapper().deleteBatchIds(ids);
        return i;
    }


    @DataSource("slave1")
    public Integer deleteAllMap(List<String> names){
        return testService.getBaseMapper().deleteBatchIds(names);
    }

}
